//
//  ImageLable.m
//  YIJU2.0-HD
//
//  Created by 张金国 on 16/5/13.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "ImageLable.h"
#import "Masonry.h"

#define currentBtnTitleColor [UIColor colorWithWhite:0.3882 alpha:1.0]//button的title颜色

@interface ImageLable ()

@property (nonatomic, strong)UIImageView   *imageView;

@property (nonatomic ,strong)UILabel       *label;

@end

@implementation ImageLable

#pragma mark - init

- (instancetype)initWithImage:(NSString *)image titleName:(NSString *)titleName {
    if (self = [super init]) {
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 5.0f;
        self.imageView.image = [UIImage imageNamed:image];
        self.imageView.tag = 100;
        self.label.text = titleName;
        self.label.tag = 101;
        [self setupConstraints];
    }
    return self;
}

#pragma mark - private
- (void)setupConstraints {
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(TenOffsetViewMargin);
        make.left.equalTo(self.mas_left);
        make.bottom.equalTo(self.mas_bottom).offset(-TenOffsetViewMargin);
        make.width.equalTo(self.mas_height);
    }];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self);
        make.left.equalTo(self.imageView.mas_right);
    }];

}

#pragma mark - getter

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc]init];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
    }
    return _imageView;
}

- (UILabel *)label {
    if (!_label) {
        _label = [[UILabel alloc]init];
        _label.textColor = currentBtnTitleColor;
        [self addSubview:_label];
    }
    return _label;
}



@end
